
//金额转换

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //输入金额
        Scanner scanner = new Scanner(System.in);
        int money = 0;

        //判断金额是否合法
        while(true){
            System.out.println("请输入金额：");
            money = scanner.nextInt();
            if(money >= 0 && money <= 9999999){
                break;
            }else {
                System.out.println("输入金额错误，请重新输入");
            }
        }

        //金额转大写字符串
        String moneyString = "";
        while(money > 0 ){
            int number = money % 10;
            money /= 10;
            moneyString = bigMoneyString(number) + moneyString;
        }
        //System.out.println(moneyString);

        //补前位零
        int count = moneyString.length();
        for (int i = 0; i < 7 - count; i++) {
            moneyString = "零" + moneyString;
        }
        //System.out.println(moneyString);

        //设置单位数组
        String[] arr = {"佰","拾","万","仟","佰","拾","元"};

        //金额大写+单位
        String moneyArr = "";
        for (int i = 0; i < arr.length; i++) {
            moneyArr = moneyArr + moneyString.charAt(i) + arr[i];
        }

        System.out.println(moneyArr);
    }

    //转大写
    public static String bigMoneyString(int number){
        String[] bigString = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        return bigString[number];
    }
}
